<?php
/**
 * Created by PhpStorm.
 * User: j28981
 * Date: 2015/9/10
 * Time: 9:38
 * mate表模型,不继承，用静态方法
 */
class mateModel{
    static public function getList(){
        $sql = "select * from #__mates order by mates_id desc";
        return Db::queryAll($sql);
    }
    public static function addMate($insert_array){
        $fields = $values = '';
        foreach($insert_array as $k=>$v){
            $fields.= "$k,";
            $values.= "'$v',";
        }
        $fields = rtrim($fields,',');
        $values = trim($values,',');
        $sql = "insert into #__mates ($fields) values ($values)";
        return Db::Insert($sql);
    }
    public function updateMate($array,$where){
        $update_str = '';
        foreach($array as $k=>$v){
            $update_str.="$k='$v',";
        }
        $update_str = rtrim($update_str,',');
        $sql = "update #__mates set $update_str where $where";
        return Db::Update($sql);
    }
}